#include "ConCtx.h"

ConCtx::ConCtx()
{
}

void ConCtx::doConverse(std::istream& istr, 
				 std::ostream& ostr, 
				 std::ostream& estr)
{
	ostr << "Welcome to Saby " << getMainVersion() << "." << getSubVersion()
		<< " revise " << getAmendmentVersion() << std::endl << std::endl;

	std::string line;
	ostr << "[Saby Ready]$ ";
	while(std::getline(istr, line))
	{
		if(line == "exit" || line == "quit" || line == "exit()" || line == "quit()")
			break;

		int nResult = runScript(line);
		while(nResult == RUN_NOTEND)
		{
			ostr << "  Expect " << getDesire() << "]$ ";
			
			if(!std::getline(istr, line))
				break;

			nResult = continueScript(line);
		}

		if(nResult != RUN_SUCCESS)
			reportError(estr);
		
		ostr << "[Saby Ready]$ ";
	}

	ostr << "Bye." << std::endl;
}